package cx.zan.service;

import cx.zan.dao.ProductDao;
import cx.zan.domain.PageBean;
import cx.zan.domain.Product;

import java.sql.SQLException;
import java.util.List;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/4/1 9:42
 */
public class ProductService {
    private ProductDao productDao = new ProductDao();

    /**
     * 查询热销产品
     *
     * @return
     * @throws SQLException
     */
    public List<Product> findhot() throws SQLException {
        return productDao.findhot();
    }

    /**
     * 根据分类cid查询
     *
     * @param cid
     * @return
     */
    public List<Product> findProductByCid(String cid) {
        return productDao.findProductByCid(cid);
    }

    /**
     * 根据pid查询
     *
     * @param pid
     * @return
     */
    public Product findById(String pid) {
        return productDao.findById(pid);
    }

    /**
     * 分类分页查询
     *
     * @param cid
     * @param pageBean
     * @return
     */
    public PageBean<Product> findProductByCidPageBean(String cid, PageBean pageBean) {
        //查询
        List<Product> list = productDao.findProductByCidPageBean(cid, pageBean);

        //查询总条数
        Long count = productDao.totalCountByCid(cid);


        pageBean.setTotal(Math.toIntExact(count));
        pageBean.setData(list);
        return pageBean;
    }

    public List<Product> findAll() {
       return productDao.findAll();
    }

    public void insert(Product product) {
        productDao.insert(product);
    }
}
